package xpn.platform.modules.sys.permission;

import javax.script.ScriptException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xpn.platform.common.repository.XpnRepositoryController;

@RepositoryRestController
@RestController
@RequestMapping("permissions")
public class SysPermissionController extends XpnRepositoryController<SysPermission, Long> {

	@Autowired
	SysPermissionService permissionService;

	/**
	 * 授权检查服务。检查指定的授权是否成立
	 * 
	 * @param permissions
	 *            ：需要检查的授权数组
	 * @return
	 * @throws ScriptException
	 */
	@PostMapping("service")
	public Object checkPermissions(@RequestBody(required = true) CheckPermissionRequest request) throws ScriptException {
		return permissionService.checkPermission(request);
	}
}
